<template>
  <div>
    <FormPanel ref="form" :list="formList" formType="add" :isSubmitBtn="false" labelWidth="120" />
    <!-- @formChange="changeHandle" -->
    <FilterTable
      ref="basetable"
      :columns="columns"
      :fetchapi="fetchapi"
      :params="params"
      :dataSource="tableList"
      columnsRef="partInventoryManagerInventoryManagerDetailStock"
      :onColumnsChange="columns => (this.columns = columns)"
    />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <p class="test">说明:成本价不含税</p>
      <el-button @click="closeDrawer(1)">取 消</el-button>
    </div>
  </div>
</template>
<script>
import { getDealertCode, getfindStorageCode, getquerypartGroupCodes, getpartInfos, getStockOutInQuantity } from '@/api/part/inventoryManager/inventoryManager/index';
import { dictionary } from '@/utils/dictMixin';
import { queryUnitCode } from '@/api/part/partInfo';
import { getBrand } from '@/api/repair/basicParameters';
export default {
  mixins: [dictionary],
  props: ['getdata'],
  data() {
    return {
      formList: this.createFrom(),
      fetchParams: {
        dmsFuncId: 30101500,
        _: 1566905683555
      },
      commitData: {},
      fetchapi: getStockOutInQuantity, // 下方table查询方法
      params: Object.assign({}, { xhrAbort: false }, { partNo: this.getdata.partNo, storageCode: this.getdata.storageCode }),
      tableList: [],
      columns: this.createTable()
    };
  },
  created() {
    this.getDictlist();
    this.initData();
  },
  mounted() {},
  methods: {
    // 查询品牌
    async getBrand() {
      try {
        // const res = await getBrandList();
        const res = await getBrand();
        this.formList.find(item => item.fieldName == 'brand').itemList = res.data.map(x => ({ text: x.BRAND_NAME, value: x.BRAND_CODE + '' }));
      } catch (error) {}
    },
    // 获取数据字典
    initData() {
      for (let i in this.getdata) {
        for (let j = 0; j < this.formList.length; j++) {
          if (this.formList[j].fieldName == i) {
            this.formList[j].initialValue = this.getdata[i];
          }
          if (this.formList[j].fieldName == 'minPackage') {
            this.formList[j].initialValue = this.getdata['packageLiaght'];
          }
        }
      }
    },
    createFrom() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'storageCode',
          placeholder: '请选择',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '税率',
          fieldName: 'taxRate',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '不含税成本单价',
          fieldName: 'costPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '库位代码',
          fieldName: 'storagePositionCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '出库单价',
          fieldName: 'costOutPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '不含税成本金额',
          fieldName: 'costAmount',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partNo',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '库存数量',
          fieldName: 'instructPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '最新进货价',
          fieldName: 'latestPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '锁定量',
          fieldName: 'lockedQuantity',
          initialValue: '',
          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '建议销售价',
        //   fieldName: 'notTaxInstructPrice',
        //   initialValue: '',
        //   disabled: true
        // },
        {
          type: 'SELECT',
          label: '单位',
          fieldName: 'unitCode',
          initialValue: '',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '安全库存',
          fieldName: 'safeStock',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '销售限价',
          fieldName: 'limitPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '拼音代码',
          fieldName: 'spellCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '最小库存',
          fieldName: 'minStock',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '索赔价',
          fieldName: 'claimPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '九大类',
          fieldName: 'partMainType',
          initialValue: '',
          itemList: this.createDictList('8094'),
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '最大库存',
          fieldName: 'maxStock',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '网点价',
          fieldName: 'salesPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '配件类别',
          fieldName: 'partGroupCode',
          initialValue: '',
          itemList: this.createDictList('8075'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '最小包装数',
          fieldName: 'minPackage',
          initialValue: '',
          disabled: true
        },
        // {
        //   type: 'INPUT_NUMBER',
        //   precision: 2,
        //   label: '终端建议零售价格',
        //   fieldName: 'insurancePrice',
        //   initialValue: '',
        //   disabled: true
        // },
        // {
        //   type: 'INPUT',
        //   label: '替代配件',
        //   fieldName: 'optionNo',
        //   initialValue: '',
        //   disabled: true
        // },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '销售价',
          fieldName: 'salesPrice',
          initialValue: '',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          initialValue: '',
          disabled: true
        }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },
        {
          title: '年度',
          dataIndex: 'YEAR',
          sorter: true,
          filter: true,
          filterType: 'input'
          // render: props => {
          //   return <span>{props.row.MOUTH}</span>;
          // }
        },
        {
          title: '月度',
          dataIndex: 'month',
          sorter: true,
          filter: true,
          filterType: 'input'
          // render: props => {
          //   return <span>{props.row.YEAR}</span>;
          // }
        },
        {
          title: '出库数量',
          dataIndex: 'outQuantity',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '入库数量',
          dataIndex: 'inQuantity',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        }
      ];
    },

    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close', false);
      }
    },
    // 获取数据字典
    async getDictlist() {
      const res4 = await queryUnitCode();
      this.formList.find(item => item.fieldName == 'unitCode').itemList = res4.data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
      let res = (await getfindStorageCode(this.fetchParams)).data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE }));
      this.formList.find(item => item.fieldName === 'storageCode').itemList = res;
      // 品牌
      this.getBrand();
      // this.formList[0].itemList = res;
      // console.log(res, 'res');
      let res2 = await getpartInfos(this.fetchParams);
      this.partInfoList = res2;
      let res1 = (await getquerypartGroupCodes(this.fetchParams)).data.map(x => ({ text: x.PART_MODEL_GROUP_NAME, value: x.PART_MODEL_GROUP_CODE }));
    }
  }
};
</script>
<style lang="less" scoped>
.test {
  text-align: left;
  color: red;
  display: block;
  float: left;
}
</style>
